#region Using Directives

using System;
using System.Drawing;
using System.Web.UI;
using System.ComponentModel;

#endregion

namespace Web.Google
{
    [ParseChildren(true, "Stops"), PersistChildren(false)]
    public class LinearGradientFill : Fill
    {
        #region Fields

        private GradientFillStopCollection stops = null;

        #endregion

        #region Constructors

        public LinearGradientFill()
        {
        }

        #endregion

        #region Properties

        [
            MergableProperty(false),
            PersistenceMode(PersistenceMode.InnerDefaultProperty),
        ]
        public GradientFillStopCollection Stops
        {
            get
            {
                if (stops == null)
                {
                    stops = new GradientFillStopCollection();
                    if (base.IsTrackingViewState)
                    {
                        stops.TrackViewState();
                    }
                }
                return stops;
            }
        }

        public int Angle
        {
            get
            {
                object o = ViewState["Angle"];
                return o == null ? 0 : (int)o;
            }
            set { ViewState["Angle"] = value; }
        }

        #endregion

        #region Methods

        public override string ToString()
        {
            DelimitedList<string> options = new DelimitedList<string>();
            options.Add(EnumHelper.GetEnumDescription(Type));
            options.Add("lg");
            options.Add(Angle.ToString());
            foreach (GradientFillStop stop in Stops)
            {
                options.Add(ColorHelper.ColorToHexString(stop.Color));
                options.Add(stop.Offset.ToString());
            }
            return options.ToString();
        }

        public override int GetHashCode()
        {
            return ToString().GetHashCode();
        }

        #endregion
    }
}